﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using SyncList.Business.ValueObject;

namespace SyncList.UserInterface
{
	/// <summary>
	/// Interaction logic for UCMenuBar.xaml
	/// </summary>
	public partial class UCMenuBar : UserControl, INotifyPropertyChanged
	{

        private string _userName = "<Anonymous>";

        /// <summary>
        /// Action à effectuer si l'on quitte
        /// </summary>
        private Action _exitAction = null;

        /// <summary>
        /// Constructeur
        /// </summary>
		public UCMenuBar()
		{
			this.InitializeComponent();
            this.BtnExit.Click += new RoutedEventHandler(BtnExit_Click);
            this.BtnSettings.Click += new RoutedEventHandler(BtnSettings_Click);

            this.DataContext = this;


            // - Action par défaut
            _exitAction = () => Application.Current.Shutdown();
		}


        /// <summary>
        /// Réglages généraux de l'application
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void BtnSettings_Click(object sender, RoutedEventArgs e)
        {
            // - Lecture des Settings dans le DataContext
            SyncListSettings settings = (SyncListSettings)this.DataContext;
            WindowsAccessor.OpenApplicationSettings(settings);
        }

        /// <summary>
        /// Quitter
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void BtnExit_Click(object sender, RoutedEventArgs e)
        {
            if (ExitAction != null)
                ExitAction();
        }



        /// <summary>
        /// Nom de l'utilisateur
        /// </summary>
        public string UserName
        {
            get { return (_userName); }
            set { _userName = value; OnPropertyChanged("UserName"); }
        }


        /// <summary>
        /// Action à effectuer si l'on quitte
        /// </summary>
        public Action ExitAction
        {
            get { return (_exitAction); }
            set { _exitAction = value; }
        }


        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

    }
}